package utils.json.serializer;

import java.lang.reflect.Type;

import utils.Page;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

/**
 * @author ultrafrog
 * @version 1.0, 2014-11-12
 * @since 1.0
 */
public class PageSerializer implements JsonSerializer<Page<?>> {

	/* (non-Javadoc)
	 * @see com.google.gson.JsonSerializer#serialize(java.lang.Object, java.lang.reflect.Type, com.google.gson.JsonSerializationContext)
	 */
	@Override
	public JsonElement serialize(Page<?> val, Type type, JsonSerializationContext ctx) {
		JsonObject obj = new JsonObject();
		obj.add("content", ctx.serialize(val.getContent()));
		obj.addProperty("page", val.getPage());
		obj.addProperty("size", val.getSize());
		obj.addProperty("total", val.getTotal());
		obj.addProperty("totalPage", val.getTotalPage());
		return obj;
	}
}
